//
//  HNSH_ChatReceiveRedChangeAlert.m
//  NongYe
//
//  Created by 李宇廷 on 2023/2/6.
//

#import "HNSH_ChatReceiveRedChangeAlert.h"
#import "HNSH_PopupController.h"

@interface HNSH_ChatReceiveRedChangeAlert ()
/* nyPopView */
@property(nonatomic, strong) HNSH_PopupController *nyPopView;
@end

@implementation HNSH_ChatReceiveRedChangeAlert

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (void)showView {
    self.nyPopView = [[HNSH_PopupController alloc]init];
    self.nyPopView.dismissOnMaskTouched = YES;
    self.nyPopView.layoutType = PopupLayoutTypeBottom;
    self.nyPopView.slideStyle = PopupSlideStyleFade;
    [self.nyPopView presentContentView:self duration:0.25 springAnimated:YES inView:kSTWindow];
    [self clipCornerWithView:self.nyPopView.popupView cornerWidth:16 cornerType:UIRectCornerTopLeft|UIRectCornerTopRight];
}

- (void)closeView {
    [self.nyPopView dismissWithDuration:0.25 springAnimated:YES];
}

- (void)configUI {
    NSArray *titles = @[@"收到的红包",@"发出的红包",@"取消"];
    __weak __typeof(&*self)weakSelf = self;
    for (int i = 0; i < titles.count; i ++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 52*i, kScreenWidth, 52);
        [button setTitle:titles[i] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        if (i == 2) {
            [button setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        }
        [self addSubview:button];
        button.tag = i;
        [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            UIButton *selectButton = x;
            if (weakSelf.typeBlock) {
                weakSelf.typeBlock(selectButton.tag);
            }
            [weakSelf closeView];
        }];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
